/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * EditChildDlg.java
 *
 * Created on May 9, 2010, 8:28:02 PM
 */
package com.aptech.childcare.gui;

import com.aptech.childcare.buz.ChildcareBuz;
import com.aptech.childcare.entities.Child;
import java.awt.Image;
import java.io.IOException;
import java.sql.Date;
import java.util.Calendar;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import javax.swing.*;

/**
 *
 * @author BaoTien
 */
public class EditChildDlg extends java.awt.Dialog {

    ChildcareBuz buz = new ChildcareBuz();
    String fileimage;

    /** Creates new form EditChildDlg */
    public EditChildDlg(java.awt.Frame parent, boolean modal) {
        super(parent, modal);

        /**
         *
         */
        ImageIcon icon = new ImageIcon(getClass().getResource("../icon/logo.png"));
        Image image = icon.getImage();
        setIconImage(image);
        /**
         *
         */
        try {
            com.jgoodies.looks.plastic.PlasticLookAndFeel.setCurrentTheme(new com.jgoodies.looks.plastic.theme.ExperienceBlue());
            UIManager.setLookAndFeel("com.birosoft.liquid.LiquidLookAndFeel");
            SwingUtilities.updateComponentTreeUI(this);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(MainFrm.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            Logger.getLogger(MainFrm.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(MainFrm.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedLookAndFeelException ex) {
            Logger.getLogger(MainFrm.class.getName()).log(Level.SEVERE, null, ex);
        }
        initComponents();
        setLocationRelativeTo(null);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        btnEdit = new javax.swing.JButton();
        btnCancel = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        txtLastName = new javax.swing.JTextField();
        cbSex = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        dcBirthday = new com.toedter.calendar.JDateChooser();
        jLabel7 = new javax.swing.JLabel();
        txtFirstName = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        txtClassID = new javax.swing.JTextField();
        txtAddress = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        lbImage = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        txtChildID = new javax.swing.JTextField();
        jPanel5 = new javax.swing.JPanel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        txtCurrentmedication = new javax.swing.JTextField();
        txtPastIllness = new javax.swing.JTextField();
        txtDoctorName = new javax.swing.JTextField();
        txtDoctorPhone = new javax.swing.JTextField();
        jPanel4 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        txtParentName = new javax.swing.JTextField();
        txtWorkNumber = new javax.swing.JTextField();
        txtParentPhone = new javax.swing.JTextField();
        txtParentEmail = new javax.swing.JTextField();
        jPanel6 = new javax.swing.JPanel();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        txtNextOfKinContact = new javax.swing.JTextField();
        dcRegistrationDate = new com.toedter.calendar.JDateChooser();
        dcDateReceived = new com.toedter.calendar.JDateChooser();
        jLabel15 = new javax.swing.JLabel();

        setResizable(false);
        setTitle("Edit Information of Child");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                closeDialog(evt);
            }
        });

        jPanel1.setNextFocusableComponent(txtLastName);
        jPanel1.setLayout(new java.awt.GridBagLayout());

        btnEdit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/aptech/childcare/icon/edit.png"))); // NOI18N
        btnEdit.setText("Edit");
        btnEdit.setMaximumSize(new java.awt.Dimension(85, 25));
        btnEdit.setMinimumSize(new java.awt.Dimension(85, 25));
        btnEdit.setNextFocusableComponent(btnCancel);
        btnEdit.setPreferredSize(new java.awt.Dimension(85, 25));
        btnEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditActionPerformed(evt);
            }
        });
        jPanel2.add(btnEdit);

        btnCancel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/aptech/childcare/icon/Cancel-2-16x16.png"))); // NOI18N
        btnCancel.setText("Cancel");
        btnCancel.setNextFocusableComponent(txtLastName);
        jPanel2.add(btnCancel);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.insets = new java.awt.Insets(10, 7, 10, 7);
        jPanel1.add(jPanel2, gridBagConstraints);

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Detail Child", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14), new java.awt.Color(153, 153, 255))); // NOI18N
        jPanel3.setLayout(new java.awt.GridBagLayout());

        jLabel3.setText("Sex ");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel3.add(jLabel3, gridBagConstraints);

        jLabel6.setText("Last Name ");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
        jPanel3.add(jLabel6, gridBagConstraints);

        txtLastName.setColumns(15);
        txtLastName.setNextFocusableComponent(txtFirstName);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel3.add(txtLastName, gridBagConstraints);

        cbSex.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Male", "Female" }));
        cbSex.setNextFocusableComponent(dcBirthday);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
        jPanel3.add(cbSex, gridBagConstraints);

        jLabel4.setText("Birthday ");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel3.add(jLabel4, gridBagConstraints);

        dcBirthday.setMinimumSize(new java.awt.Dimension(110, 20));
        dcBirthday.setPreferredSize(new java.awt.Dimension(110, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel3.add(dcBirthday, gridBagConstraints);

        jLabel7.setText("First Name");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
        jPanel3.add(jLabel7, gridBagConstraints);

        txtFirstName.setColumns(12);
        txtFirstName.setNextFocusableComponent(cbSex);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel3.add(txtFirstName, gridBagConstraints);

        jLabel1.setText("Class ID");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel3.add(jLabel1, gridBagConstraints);

        txtClassID.setColumns(10);
        txtClassID.setEditable(false);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel3.add(txtClassID, gridBagConstraints);

        txtAddress.setColumns(15);
        txtAddress.setMinimumSize(new java.awt.Dimension(200, 20));
        txtAddress.setNextFocusableComponent(txtCurrentmedication);
        txtAddress.setPreferredSize(new java.awt.Dimension(200, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 6;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel3.add(txtAddress, gridBagConstraints);

        jLabel14.setText("Address     ");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 6;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel3.add(jLabel14, gridBagConstraints);

        lbImage.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbImage.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        lbImage.setMaximumSize(new java.awt.Dimension(100, 100));
        lbImage.setMinimumSize(new java.awt.Dimension(100, 100));
        lbImage.setPreferredSize(new java.awt.Dimension(100, 100));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridheight = 4;
        gridBagConstraints.insets = new java.awt.Insets(4, 15, 4, 4);
        jPanel3.add(lbImage, gridBagConstraints);

        jLabel19.setText("Child ID");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
        jPanel3.add(jLabel19, gridBagConstraints);

        txtChildID.setColumns(15);
        txtChildID.setEditable(false);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel3.add(txtChildID, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel1.add(jPanel3, gridBagConstraints);

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "History disease", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14), new java.awt.Color(153, 153, 255))); // NOI18N
        jPanel5.setMinimumSize(new java.awt.Dimension(300, 180));
        jPanel5.setPreferredSize(new java.awt.Dimension(300, 180));
        jPanel5.setLayout(new java.awt.GridBagLayout());

        jLabel10.setText("Doctor Phone");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 7, 5, 7);
        jPanel5.add(jLabel10, gridBagConstraints);

        jLabel11.setText("Currentmedication");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 7, 5, 7);
        jPanel5.add(jLabel11, gridBagConstraints);

        jLabel12.setText("PastIllness");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 7, 5, 7);
        jPanel5.add(jLabel12, gridBagConstraints);

        jLabel13.setText("Doctor Name");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 7, 5, 7);
        jPanel5.add(jLabel13, gridBagConstraints);

        txtCurrentmedication.setColumns(15);
        txtCurrentmedication.setMinimumSize(new java.awt.Dimension(200, 20));
        txtCurrentmedication.setNextFocusableComponent(txtPastIllness);
        txtCurrentmedication.setPreferredSize(new java.awt.Dimension(200, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel5.add(txtCurrentmedication, gridBagConstraints);

        txtPastIllness.setColumns(15);
        txtPastIllness.setNextFocusableComponent(txtDoctorName);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel5.add(txtPastIllness, gridBagConstraints);

        txtDoctorName.setColumns(15);
        txtDoctorName.setNextFocusableComponent(txtDoctorPhone);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel5.add(txtDoctorName, gridBagConstraints);

        txtDoctorPhone.setColumns(15);
        txtDoctorPhone.setNextFocusableComponent(txtParentName);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel5.add(txtDoctorPhone, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel1.add(jPanel5, gridBagConstraints);

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Detail Parent", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14), new java.awt.Color(153, 153, 255))); // NOI18N
        jPanel4.setVerifyInputWhenFocusTarget(false);
        jPanel4.setLayout(new java.awt.GridBagLayout());

        jLabel2.setText("Name");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel4.add(jLabel2, gridBagConstraints);

        jLabel5.setText("Work Number");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel4.add(jLabel5, gridBagConstraints);

        jLabel8.setText("Phone");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel4.add(jLabel8, gridBagConstraints);

        jLabel9.setText("Email");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel4.add(jLabel9, gridBagConstraints);

        txtParentName.setColumns(15);
        txtParentName.setNextFocusableComponent(txtWorkNumber);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel4.add(txtParentName, gridBagConstraints);

        txtWorkNumber.setColumns(15);
        txtWorkNumber.setNextFocusableComponent(txtParentPhone);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel4.add(txtWorkNumber, gridBagConstraints);

        txtParentPhone.setColumns(15);
        txtParentPhone.setNextFocusableComponent(txtParentEmail);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel4.add(txtParentPhone, gridBagConstraints);

        txtParentEmail.setColumns(15);
        txtParentEmail.setNextFocusableComponent(txtNextOfKinContact);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel4.add(txtParentEmail, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel1.add(jPanel4, gridBagConstraints);

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Other information", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14), new java.awt.Color(153, 153, 255))); // NOI18N
        jPanel6.setLayout(new java.awt.GridBagLayout());

        jLabel16.setText("Registration Date");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel6.add(jLabel16, gridBagConstraints);

        jLabel17.setText("Date Received");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel6.add(jLabel17, gridBagConstraints);

        jLabel18.setText("NextOfKinContact");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel6.add(jLabel18, gridBagConstraints);

        txtNextOfKinContact.setColumns(15);
        txtNextOfKinContact.setNextFocusableComponent(dcRegistrationDate);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel6.add(txtNextOfKinContact, gridBagConstraints);

        dcRegistrationDate.setNextFocusableComponent(dcDateReceived);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel6.add(dcRegistrationDate, gridBagConstraints);

        dcDateReceived.setNextFocusableComponent(btnEdit);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel6.add(dcDateReceived, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        jPanel1.add(jPanel6, gridBagConstraints);

        jLabel15.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel15.setText("Edit Child");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.insets = new java.awt.Insets(20, 4, 20, 4);
        jPanel1.add(jLabel15, gridBagConstraints);

        add(jPanel1, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /** Closes the dialog */
    private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
        setVisible(false);
        dispose();
    }//GEN-LAST:event_closeDialog

    private void btnEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditActionPerformed
        try {
            // TODO add your handling code here:
            Child ch = new Child();
            if (txtLastName.getText().equals("")) {
                JOptionPane.showMessageDialog(this, "Please,Enter LastName");
                txtLastName.requestFocus();
                return;
            }
            if (txtFirstName.getText().equals("")) {
                JOptionPane.showMessageDialog(this, "Please,Enter FirstName");
                txtFirstName.requestFocus();
                return;
            }
            if (txtAddress.getText().equals("")) {
                JOptionPane.showMessageDialog(this, "Please,Enter Address");
                txtAddress.requestFocus();
                return;
            }
            if (txtParentName.getText().equals("")) {
                JOptionPane.showMessageDialog(this, "Please,Enter Parent Name");
                txtParentName.requestFocus();
                return;
            }
            Calendar ca = Calendar.getInstance();
            Date birthday = new Date(ca.getTimeInMillis());
            if (dcBirthday.getDate() == null) {
                JOptionPane.showMessageDialog(this, "Please, enter  Birthday .");
                dcBirthday.requestFocus();
                return;
            } else if (dcBirthday.getDate() != null) {
                ca.setTime(dcBirthday.getDate());
                if (dcBirthday.getCalendar().getTime().after(birthday)) {
                    JOptionPane.showMessageDialog(this, "Birthday Date < today");
                    dcBirthday.setDate(null);
                    dcBirthday.requestFocus();
                    return;
                }
            }
            String strPhone = "[0-9]{7,11}";
            if (txtParentPhone.getText().equals("")) {
                JOptionPane.showMessageDialog(this, "Please,Enter Phone");
                txtParentPhone.requestFocus();
                return;
            } else if (!Pattern.matches(strPhone, txtParentPhone.getText())) {
                JOptionPane.showMessageDialog(this, "Phone number must be greater than 7 characters and numbers.");
                txtParentPhone.requestFocus();
                txtParentPhone.selectAll();
                return;
            }
            String strEmail = "\\w+(\\.\\w+)*@\\w+(\\.\\w+)+";
            if (txtParentEmail.getText().length() != 0) {
                if (!Pattern.matches(strEmail, txtParentEmail.getText())) {
                    JOptionPane.showMessageDialog(this, "Email no match!");
                    txtParentEmail.requestFocus();
                    txtParentEmail.selectAll();
                    return;
                }
            }
            Date startDate = new Date(ca.getTimeInMillis());
            if (dcRegistrationDate.getDate() == null) {
                JOptionPane.showMessageDialog(this, "Please, enter Registration Date .");
                dcRegistrationDate.requestFocus();
                return;
            } else if (dcRegistrationDate.getDate() != null) {
                ca.setTime(dcRegistrationDate.getDate());
                if (dcBirthday.getDate().after(dcRegistrationDate.getDate())) {
                    JOptionPane.showMessageDialog(this, "Registration Date > Birthday");
                    dcRegistrationDate.setDate(null);
                    dcRegistrationDate.requestFocus();
                    return;
                }
            }
            Date endDate = new Date(ca.getTimeInMillis());
            if (dcDateReceived.getDate() == null) {
                JOptionPane.showMessageDialog(this, "Please, enter Start Date .");
                dcDateReceived.requestFocus();
                return;
            } else if (dcDateReceived.getDate() != null) {
                ca.setTime(dcDateReceived.getDate());
                if (dcRegistrationDate.getDate().after(dcDateReceived.getDate())) {
                    JOptionPane.showMessageDialog(this, " End Date > Start Date");
                    dcDateReceived.setDate(null);
                    dcDateReceived.requestFocus();
                    return;
                }
            }
            ch.setChildID(Integer.parseInt(txtChildID.getText()));
            ch.setLastName(txtLastName.getText());
            ch.setFirstName(txtFirstName.getText());
            ch.setSex(String.valueOf(cbSex.getSelectedItem()));
            ch.setBirthday(startDate);
            ch.setClassID(Integer.parseInt(txtClassID.getText()));
            ch.setAddress(txtAddress.getText());
            ch.setCurrentMedication(txtCurrentmedication.getText());
            ch.setDoctorName(txtDoctorName.getText());
            ch.setPasrIllness(txtPastIllness.getText());
            ch.setDoctorPhone(txtDoctorPhone.getText());
            ch.setParentName(txtParentName.getText());
            ch.setParentEmail(txtParentEmail.getText());
            ch.setParentPhone(txtParentPhone.getText());
            ch.setParentWorkNumber(txtWorkNumber.getText());
            ch.setNextOfKinContact(txtNextOfKinContact.getText());
            ch.setRegistrationDate(endDate);
            ch.setDateReceived(birthday);
            if (buz.storeChild(ch)) {
                JOptionPane.showMessageDialog(this, buz.chdao.getLastError());
                this.dispose();
            } else {
                JOptionPane.showMessageDialog(this, buz.chdao.getLastError());
            }
        } catch (IOException ex) {
            Logger.getLogger(EditChildDlg.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btnEditActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                EditChildDlg dialog = new EditChildDlg(new java.awt.Frame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancel;
    private javax.swing.JButton btnEdit;
    protected javax.swing.JComboBox cbSex;
    protected com.toedter.calendar.JDateChooser dcBirthday;
    protected com.toedter.calendar.JDateChooser dcDateReceived;
    protected com.toedter.calendar.JDateChooser dcRegistrationDate;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    protected javax.swing.JLabel lbImage;
    protected javax.swing.JTextField txtAddress;
    protected javax.swing.JTextField txtChildID;
    protected javax.swing.JTextField txtClassID;
    protected javax.swing.JTextField txtCurrentmedication;
    protected javax.swing.JTextField txtDoctorName;
    protected javax.swing.JTextField txtDoctorPhone;
    protected javax.swing.JTextField txtFirstName;
    protected javax.swing.JTextField txtLastName;
    protected javax.swing.JTextField txtNextOfKinContact;
    protected javax.swing.JTextField txtParentEmail;
    protected javax.swing.JTextField txtParentName;
    protected javax.swing.JTextField txtParentPhone;
    protected javax.swing.JTextField txtPastIllness;
    protected javax.swing.JTextField txtWorkNumber;
    // End of variables declaration//GEN-END:variables
}
